package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.ArchiveStocktaking;
import com.hiultra.archive.service.IArchiveStocktakingService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 盘点数据Controller
 *
 * @author paidaxing
 * @date 2024-07-31
 */
@RestController
@RequestMapping("/archive/ArchiveStocktaking")
public class ArchiveStocktakingController extends BaseController
{
    @Autowired
    private IArchiveStocktakingService archiveStocktakingService;

    /**
     * 查询盘点数据列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveStocktaking archiveStocktaking)
    {
        startPage();
        List<ArchiveStocktaking> list = archiveStocktakingService.selectArchiveStocktakingList(archiveStocktaking);
        return getDataTable(list);
    }

    /**
     * 导出盘点数据列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:export')")
    @Log(title = "盘点数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveStocktaking archiveStocktaking)
    {
        List<ArchiveStocktaking> list = archiveStocktakingService.selectArchiveStocktakingList(archiveStocktaking);
        ExcelUtil<ArchiveStocktaking> util = new ExcelUtil<ArchiveStocktaking>(ArchiveStocktaking.class);
        util.exportExcel(response, list, "盘点数据数据");
    }

    /**
     * 获取盘点数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(archiveStocktakingService.selectArchiveStocktakingById(id));
    }

    /**
     * 新增盘点数据
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:add')")
    @Log(title = "盘点数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveStocktaking archiveStocktaking)
    {
        return toAjax(archiveStocktakingService.insertArchiveStocktaking(archiveStocktaking));
    }

    /**
     * 修改盘点数据
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:edit')")
    @Log(title = "盘点数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveStocktaking archiveStocktaking)
    {
        return toAjax(archiveStocktakingService.updateArchiveStocktaking(archiveStocktaking));
    }

    /**
     * 删除盘点数据
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:remove')")
    @Log(title = "盘点数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(archiveStocktakingService.deleteArchiveStocktakingByIds(ids));
    }
    /**
     * 根据taskBoxId获取盘点档案列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:query')")
    @GetMapping(value = "/archiveList/{taskBoxId}")
    public AjaxResult selectPDListByBoxNo(@PathVariable("taskBoxId") String taskBoxId)
    {
        return AjaxResult.success(archiveStocktakingService.selectArchiveListByTaskBoxId(taskBoxId));
    }

    /**
     * 修改盘点单-盘点档案
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveStocktaking:editArchiveStockList')")
    @Log(title = "修改盘点单-盘点档案", businessType = BusinessType.UPDATE)
    @PostMapping("/editArchiveStocktaking")
    public AjaxResult editArchiveStocktaking(@RequestBody ArchiveStocktaking archiveStocktaking)
    {
        return toAjax(archiveStocktakingService.editArchiveStocktaking(archiveStocktaking));
    }
}
